home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / lib / mathlib / libfft / TRY / c_speed1d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.3 KB  |  208 lines

  1. #include <stdio.h>
  2. #include <sys/time.h>
  3.  
  4. #include "fft.h"
  5. #include "constant.h"
  6.  
  7. /*
  8. *   Precision Dependant declarations
  9. */
  10.  
  11. #ifdef ZOMPLEX
  12.  
  13. typedef zomplex this_type;
  14. typedef double this_half;
  15.  
  16. #define        TOLERANCE        DTOLERANCE
  17. #define        THIS_GEN        zgen_
  18. #define        THIS_FFTI        zfft1di
  19. #define        THIS_FFT        zfft1d
  20. #define        THIS_SCAL        zscal1d
  21.  
  22. #endif
  23.  
  24. #ifdef COMPLEX
  25.  
  26. typedef complex this_type;
  27. typedef float this_half;
  28.  
  29. #define        TOLERANCE        STOLERANCE
  30. #define        THIS_GEN        cgen_
  31. #define        THIS_FFTI        cfft1di
  32. #define        THIS_FFT        cfft1d
  33. #define        THIS_SCAL        cscal1d
  34.  
  35. #endif
  36.  
  37. /*    */
  38.  
  39. void inimat_();
  40. void GetArguments();
  41. void get_values();
  42.  
  43. int min_size, max_size, inc_size, is_parallel;
  44. this_type *pa, *pSave;
  45.  
  46. int timing;
  47.  
  48. static     long z_sec, z_usec;
  49. static int first_time = 1;
  50.  
  51. float second()
  52. {
  53.         struct timeval s_val;
  54.     struct timezone s_z;
  55.     float time;
  56.     long n_sec, n_usec;
  57.         gettimeofday(&s_val, &s_z);
  58.     n_sec = s_val.tv_sec;
  59.     n_usec = s_val.tv_usec;
  60.     if( first_time ) {
  61.         z_sec = n_sec;
  62.         z_usec = n_usec;
  63.         first_time =0;
  64.     }
  65.     time = (float)(n_sec-z_sec) + (float)(n_usec -z_usec) * 1.0E-6;
  66.     return( time );
  67. }
  68.  
  69. main(argc,argv)
  70. int argc;
  71. char *argv[];
  72. {
  73.     int i, j, k, n_total, is_wrong, size, inc, n_times, n_flops;
  74.     double x, y, t, emax;
  75.     this_half ratio;
  76.  
  77. /* ******************************************************* */
  78.     GetArguments( argc, argv);
  79. /* ******************************************************* */
  80.  
  81.     srandom( (123*getpid()) | 0x01);
  82.  
  83.     for( size=min_size ; size <= max_size ; size *= inc_size) { 
  84.  
  85.     n_total = ((size)*MAX_STRIDE);
  86.     pa = (this_type *)malloc( (n_total + size + FACTOR_SPACE) * sizeof(this_type));
  87.     if( !(pa) ) {
  88.         fprintf( stderr, "Could not allocate ... Exiting\n");
  89.         exit (-1);
  90.     }
  91.  
  92.     fflush(stdout);
  93.  
  94.     printf( "%4d  ", size);
  95.  
  96.     n_flops = (int) (5. * (double)size * (log((double)size)/log(2.)));
  97.     n_times = (int) (MAX_FLOPS / (double)n_flops);
  98.     if(n_times < 1) n_times =1;
  99.     ratio = 1./(double)size;
  100. /* *******************************************************
  101.     stride 1
  102. ******************************************************* */
  103.     inc = 1;
  104.     n_total = (size*inc);
  105.     pSave = pa + n_total;
  106.  
  107.     THIS_GEN(pa, &n_total);
  108.     pSave = THIS_FFTI( size, pSave);
  109.  
  110.     t = second();
  111.     for ( i = 0 ; i < n_times ; i++)  {
  112.         
  113.         is_wrong = THIS_FFT( -1, size, pa, inc, pSave);
  114.         is_wrong = THIS_FFT(  1, size, pa, inc, pSave);
  115.         THIS_SCAL( size, ratio, pa, inc);
  116.     }
  117.     t = second() - t;
  118.     if( timing)
  119.         x = t / (double)(2*n_times);
  120.     else
  121.         x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
  122.     printf("%6.4e  ", x);
  123.  
  124. /* *******************************************************
  125.     stride > 1
  126. ******************************************************* */
  127.     inc = MAX_STRIDE;
  128.     n_total = (size*inc);
  129.     pSave = pa + n_total;
  130.  
  131.     THIS_GEN(pa, &n_total);
  132.     pSave = THIS_FFTI( size, pSave);
  133.  
  134.     t = second();
  135.     for ( i = 0 ; i < n_times ; i++)  {
  136.         
  137.         is_wrong = THIS_FFT( -1, size, pa, inc, pSave);
  138.         is_wrong = THIS_FFT(  1, size, pa, inc, pSave);
  139.         THIS_SCAL( size, ratio, pa, inc);
  140.     }
  141.     t = second() - t;
  142.     if( timing)
  143.         x = t / (double)(2*n_times);
  144.     else
  145.         x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
  146.     printf("%6.4e  ", x);
  147. /* *******************************************************
  148. ******************************************************* */
  149.     printf("\n");
  150.     free(pa);
  151.     }
  152.     return (0);
  153. }
  154.  
  155. int is_random;
  156.  
  157. void GetArguments( argc, argv)
  158. int argc;
  159. char *argv[];
  160. {
  161.     int i, j, k;
  162.     int nerror = 0;
  163.  
  164. #define ON    1
  165.  
  166.     max_size = MAX_SIZE;
  167.     min_size = MIN_SIZE;
  168.     inc_size = INC_SIZE;
  169.  
  170.     is_parallel = 0;
  171.     timing = 0;
  172.  
  173. /* ******************************************************* */
  174.     for ( i = 1 ; (i < argc) && (nerror != ON) ; i ++ ) {
  175.     if( argv[i][0] == '-') {
  176.         switch ( argv[i][1]) {
  177.         case 's' :
  178.         case 'S' :  
  179.                 is_parallel = 0;
  180.                 break;
  181.         case 'p' :
  182.         case 'P' :  
  183.                 is_parallel = 1;
  184.                 break;
  185.         case 't' :
  186.         case 'T' :  
  187.                 timing = 1;
  188.                 break;
  189.         default  :  nerror = ON;
  190.         }
  191.     }
  192.     else {
  193.         if( i+1 > argc)
  194.         nerror = ON;
  195.         else { 
  196.         min_size = atoi( argv[i++]);
  197.         max_size = atoi( argv[i++]);
  198.         inc_size = atoi( argv[i]);
  199.         }
  200.     }
  201.     }
  202.     if( nerror == ON) {
  203.     fprintf( stderr, 
  204.         "Usage : %s [-p(arallel)] [n_trials]\n", argv[0]);
  205.     exit(-1);
  206.     }
  207. }
  208.